﻿// Copyright (c) Microsoft Corporation.  All rights reserved. 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WiE.Model
{
    class WiEModelException : Exception
    {
        public WiEModelException(Exception p_originalException):base ("",p_originalException)
        {
        }

        public WiEModelException(string p_strExceptionMessage):base(p_strExceptionMessage)
        {
        }

        public WiEModelException(string p_strException, Exception p_originalException) : base(p_strException,p_originalException)
        {
        }
    }

    /// <summary>
    /// This interface defines the operations expected to be provided by a data model provider to the application.  These
    /// operations typically are saving and retrival of data objects.  The application may define several implementations 
    /// for example remote data storage to a cloud provider, local data storage to a database or hybrid providers that
    /// implement occasionally connected scenarios.
    /// </summary>
    /// <remarks>
    /// 7/31/08 - Added new IsAvailable() method in preparation for Sync framework integration and to make the application
    /// a little more tolerant / efficient to network / occasionally connected models.
    /// </remarks>
    interface IWiEModel
    {
        /// <summary>
        /// Event used by data model providers to advertise that the Location History was modified.
        /// </summary>
        event EventHandler<LocationHistoryChangedArgs> RaiseLocationHistoryChangedEvent;

        /// <summary>
        /// Event used by data model to inform subscribers to the model that Device was changed.
        /// </summary>
        event EventHandler<DeviceChangedArgs> RaiseDeviceChangedEvent;

        /// <summary>
        /// Event used by data model to inform subscribers that a Member data object was changed, inserted or updated.
        /// </summary>
        event EventHandler<MemberChangedArgs> RaiseMemberChangedEvent;

        /// <summary>
        /// Retrieves the location data object associated with the location id p_guidLocationID
        /// </summary>
        /// <param name="p_guidLocationID"></param>
        /// <returns></returns>
        WiELocationDataObject GetLocation(System.Guid p_guidLocationID);

        /// <summary>
        /// Remove a single location item
        /// </summary>
        /// <param name="p_guidLocationID"></param>
        void RemoveLocation(System.Guid p_guidLocationID);

        /// <summary>
        /// Retrieve list of location data objects that were recorded / captured between start and stop time.
        /// </summary>
        /// <param name="p_dtStartTimeUTC"></param>
        /// <param name="p_dtStopTimeUTC"></param>
        /// <returns></returns>
        List<WiELocationDataObject> GetLocationHistoryBetween(DateTime p_dtStartTimeUTC, DateTime p_dtStopTimeUTC);

        /// <summary>
        /// Retrieve list of location data objects that were recorded / captured before p_dtEndTime
        /// </summary>
        /// <param name="p_dtEndTime"></param>
        /// <returns></returns>
        List<WiELocationDataObject> GetLocationHistoryBefore(DateTime p_dtEndTime);

        /// <summary>
        /// Save the location information for a device / member.
        /// </summary>
        /// <param name="p_locationDataObject"></param>
        void SaveLocation(WiELocationDataObject p_locationDataObject);

        /// <summary>
        /// Save the member
        /// </summary>
        /// <param name="p_memberDataObject"></param>
        void SaveMember(WiEMemberDataObject p_memberDataObject);

        /// <summary>
        /// Retrieves the Member using their unique ID
        /// </summary>
        /// <param name="p_guidMemberID"></param>
        /// <returns></returns>
        WiEMemberDataObject GetMember(Guid p_guidMemberID);

        /// <summary>
        /// Retrieves the member whose user name matches p_strUserName
        /// </summary>
        /// <param name="p_strUserName"></param>
        /// <returns></returns>
        WiEMemberDataObject GetMemberByUserName(string p_strUserName);

        /// <summary>
        /// Retrieves the member whose phone number matches p_strPhoneNumber;
        /// </summary>
        /// <param name="p_strPhoneNumber"></param>
        /// <returns></returns>
        WiEMemberDataObject GetMemberByPhoneNumber(string p_strPhoneNumber);

        /// <summary>
        /// Retrieve all the members stored in the model.
        /// </summary>
        /// <returns></returns>
        List<WiEMemberDataObject> GetMembers();

        /// <summary>
        /// Saves the device information
        /// </summary>
        /// <param name="p_deviceDataObject"></param>
        void SaveDevice(WiEDeviceDataObject p_deviceDataObject);

        /// <summary>
        /// Retrieves the device information using the device's unique ID.
        /// </summary>
        /// <param name="p_guidDeviceID"></param>
        /// <returns></returns>
        WiEDeviceDataObject GetDevice(System.Guid p_guidDeviceID);

        /// <summary>
        /// Retrieves the device(s) associated with a Member.
        /// </summary>
        /// <param name="p_guidMemberID"></param>
        /// <returns></returns>
        List<WiEDeviceDataObject> GetDevicesByMember(System.Guid p_guidMemberID);

        /// <summary>
        /// Retrieves all the device(s) stored in the model.
        /// </summary>
        /// <returns></returns>
        List<WiEDeviceDataObject> GetDevices();

        /// <summary>
        /// Provides a method for Model implementors to initialize their model implementation
        /// </summary>
        void Initialize();

        /// <summary>
        /// Method called when application is being exited, provides mechanism for the model to terminate
        /// any threads and free up memory and resources it was using.
        /// </summary>
        void Terminate();

        /// <summary>
        /// Method to check on the availability / accessibility of the underlying model / datastore.  
        /// </summary>
        /// <returns></returns>
        bool IsAvailable();
    }
}
